//
//  CAHeaderView.m
//  LNH
//
//  Created by twentylx on 2018/2/7.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAHeaderView.h"

@implementation CAHeaderView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {
    
}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self setNeedsUpdateConstraints];
    
    [self addSubview:self.headImageView];
    [self.headImageView addSubview:self.logoImageView];
    [self.headImageView addSubview:self.nameLabel];
}

#pragma mark layout
- (void)updateConstraints {
    [super updateConstraints];
    
    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self);
    }];
    
    [self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.headImageView);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(100);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.logoImageView);
        make.top.equalTo(self.logoImageView.mas_bottom).offset(5);
    }];
}

#pragma mark get & set
- (UIImageView *) headImageView {
    if (!_headImageView) {
        _headImageView = [UIImageView new];
        _headImageView.image = [UIImage imageNamed:@"p_header"];
        _headImageView.userInteractionEnabled = YES;
    }
    return _headImageView;
}

- (UIImageView *) logoImageView {
    if (!_logoImageView) {
        _logoImageView = [UIImageView new];
        _logoImageView.image = LMImageNamed(@"qrcode_logo");
        _logoImageView.layer.masksToBounds =YES;
        _logoImageView.layer.cornerRadius =50;
        _logoImageView.userInteractionEnabled = YES;
    }
    return _logoImageView;
}

- (UILabel *) nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.text = @"";
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.textColor = [UIColor whiteColor];
    }
    return _nameLabel;
}

@end
